﻿using System;

namespace Program11
{
    class Program
    {

        /// <summary>
        /// 递归算法与非递归算法的阶乘
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            Program pro = new Program();//创建对象

            Console.WriteLine("非递归算法:" +  pro.GetProductNotRecursive(5));
            Console.WriteLine("递归算法:" + pro.GetProductRecursive(5));
            Console.ReadKey();
        }

        public int GetProductRecursive(int n) //递归算法
        {
            if (n == 1)
            {
                return 1;
            }

            return GetProductRecursive(n - 1) * n;
        }
        public int GetProductNotRecursive(int n) //非递归算法
        {
            int p = 1;

            for (int i = 1; i <= n; i++)
            {
                p = p * i;
            }    

            return p;
        }
    }
}
